#pragma once
#include "IHelperBase.h"
#include <GameLogic/BoardLogicBase.h>
#include <ICameraSceneNode.h>
namespace catan
{
	struct IPlayerItemBuildHandler
	{
		virtual void OnBuildHouse(Handle<BuildPoint> buildPoint) = 0;
		virtual void OnBuildSelement(Handle<BuildPoint> buildPoint) = 0;
		virtual void OnBuildRoad(Handle<Edge> edge) = 0;
	};

	class PlayerItemBuildController : public IHelperBase, public ISceneNodeAnimator
	{
	public:
		static PlayerItemBuildController* CreateBuildHouse(IHelperBase*);
		static PlayerItemBuildController* CreateBuildSettlemnet(IHelperBase*);
		static PlayerItemBuildController* CreateBuildRoad(IHelperBase*);

		PlayerItemBuildController()
		{
			mBuildHandler = 0;
			mPlayerItemNode = 0;
		}
		virtual ~PlayerItemBuildController(void);

		
		void Do(IPlayerItemBuildHandler* buildHandler)
		{
			VALID(buildHandler);
			mBuildHandler = buildHandler;
			mHelper->GetSceneManager()->getActiveCamera()->addAnimator(this);
			mPlayerItemCanBuildNodes = mHelper->GetSceneManager()->getSceneNodeFromName(GetPlayerItemBuildNodeName().c_str(), mHelper->GetBoardNode());
			mPlayerItemCanBuildNodes->grab();

			OnDo();
		}

		virtual void OnDo()
		{
			ShowCanBuild();
			mPlayerItemNode = CreatePlayeyItemNode();
			mPlayerItemNode->grab();
			mPlayerItemNode->setPosition(GetMouseRay().end);
			Test();
		}

		void Test();

		void Done(int id)
		{
			mHelper->GetSceneManager()->getActiveCamera()->removeAnimator(this);
			OnDone(id);
			
		}
		virtual void animateNode(ISceneNode* node, u32 timeMs) {}

		//! Creates a clone of this animator.
		/** Please note that you will have to drop
		(IReferenceCounted::drop()) the returned pointer after calling this. */
		virtual ISceneNodeAnimator* createClone(ISceneNode* node,
				ISceneManager* newManager=0)
		{
			VALID(0);
			return NULL;
		}

		virtual bool isEventReceiverEnabled() const
		{
			return true;
		}

		virtual bool OnEvent(const SEvent& event);


		virtual void OnMoveMove();

		virtual void OnMoveLBtn();

		virtual void OnDone(int id) = 0;

		virtual const core::vector3df GetPosition(ISceneNode* checkSceneNode);
		virtual const core::vector3df GetRotate(ISceneNode* checkSceneNode);

		ISceneNode* GetMouseCanBuildNode(core::line3df* ray = 0);

		virtual std::string GetPlayerItemBuildNodeName() = 0;

		core::line3df GetMouseRay();
		virtual ISceneNode* CreatePlayeyItemNode() = 0;
		virtual void ShowCanBuild() = 0;
		IPlayerItemBuildHandler* mBuildHandler;
		ISceneNode* mPlayerItemNode;
		ISceneNode* mPlayerItemCanBuildNodes;
		typedef std::vector<ISceneNode*> ISceneNodes;
		ISceneNodes mAllBuildNodes;
	};

	
}